package hcontroller

import (
	"encoding/json"

	"advertoper/controllers"
	"advertoper/errorcode"
	"advertoper/homepageinfo/hservice"
)

type ZJTopicInfoController struct {
	controllers.SCLoginedController
}

/*添加zjTopic
{"region_code":"","clickable":1,"title":"夏天必备技能get","sub_title":"宅人必备技能"
"pic_url":"https://fscdn.qkier.com/scloud/e/b/c/d725bad2001dd6c76a189dd6e0f69",
"background_picture":"https://fscdn.qkier.com/scloud/e/b/c/d725bad2001dd6c76a189dd6e0f69",
"background_color":"#000000","starttick":1,"endtick":1499999999,
"routers":"zhjt://app.zjdj.com/webin?http://www.zhijiandaojia.com"}
*/
// @router /zjtopic/add [post]
func (p *ZJTopicInfoController) ZJTopicAdd() {
	defer p.Output("ZJTopicAdd")
	p.ForceHTTPS()

	body := p.Ctx.Input.RequestBody
	req := &hservice.ZJTopicAddReq{}
	if err := json.Unmarshal(body, req); err != nil {
		p.Resp["code"] = errorcode.EC_GL_INVALID_JSON_BODY
		p.Resp["msg"] = errorcode.Msg(errorcode.EC_GL_INVALID_JSON_BODY)
		return
	}
	code, msg := hservice.GetZJTopicInfoService().ZJTopicAdd(req)
	p.Resp["code"] = code
	p.Resp["msg"] = msg

}

/*修改zjTopic
{"id":1,"region_code":"","clickable":1,"title":"夏天必备技能get","sub_title":"宅人必备技能"
"pic_url":"https://fscdn.qkier.com/scloud/e/b/c/d725bad2001dd6c76a189dd6e0f69",
"background_picture":"https://fscdn.qkier.com/scloud/e/b/c/d725bad2001dd6c76a189dd6e0f69",
"background_color":"#000000","starttick":1,"endtick":1499999999,
"routers":"zhjt://app.zjdj.com/webin?http://www.zhijiandaojia.com","status":1}
*/
// @router /zjtopic/update [post]
func (p *ZJTopicInfoController) ZJTopicUpdate() {
	defer p.Output("ZJTopicUpdate")
	p.ForceHTTPS()

	body := p.Ctx.Input.RequestBody
	req := &hservice.ZJTopicUpdateReq{}
	if err := json.Unmarshal(body, req); err != nil {
		p.Resp["code"] = errorcode.EC_GL_INVALID_JSON_BODY
		p.Resp["msg"] = errorcode.Msg(errorcode.EC_GL_INVALID_JSON_BODY)
		return
	}
	code, msg := hservice.GetZJTopicInfoService().ZJTopicUpdate(req)
	p.Resp["code"] = code
	p.Resp["msg"] = msg

}

//web查询
// @router /zjtopic/list [get]
func (p *ZJTopicInfoController) ZJTopicInfoList() {
	defer p.Output("ZJTopicInfoList")
	p.ForceHTTPS()

	status, _ := p.GetInt("status", 1)
	data := hservice.GetZJTopicInfoService().ZJTopicInfoList(status)
	if len(data) == 0 {
		p.Resp["code"] = 101
		p.Resp["msg"] = "no data"
	} else {
		p.Resp["code"] = 0
		p.Resp["msg"] = "success"
		p.Resp["data"] = data
	}

}
